﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Models;
using BLL;
namespace AGVControlSystemPro
{
    public partial class FrmInputLandNum : Form
    {
        private LandNodeManager objLandNodeManager = new LandNodeManager();
        private LandNode currentLandNode = new LandNode();//存储当前的地标信息
        public GetInputLanNum inputLandNum;
        public FrmInputLandNum(LandNode objLandNode)
        {
            InitializeComponent();
            currentLandNode = objLandNode;//存储当前地标信息
            this.txtLandNum.Text = objLandNode.LandNum.ToString(); //显示
            this.lblLandNum.Text = objLandNode.LandNum.ToString() + "号地标已存在请重新输入!";
        }

        private void btnCertify_Click(object sender, EventArgs e)
        {

            #region 数据验证
            if (this.txtLandNum.Text.Trim().Length == 0)
            {
                MessageBox.Show("地标号不能为空！","信息提示");
                this.txtLandNum.Focus();
                return;
            }
            if (!Common.DataValidate.IsPositiveInteger(this.txtLandNum.Text.Trim()))
            {
                MessageBox.Show("地标号必须位正整数！", "信息提示");
                this.txtLandNum.Focus();
                return;
            }
            #endregion

            //数据封装
            LandNode objLandNode = new LandNode()
            {
                LandNum = Convert.ToInt32(this.txtLandNum.Text.Trim()),
                NodeName = "lbl" + this.txtLandNum.Text.Trim(),
                NodeTypeId = currentLandNode.NodeTypeId,
                X = currentLandNode.X,
                Y = currentLandNode.Y,
                ID = currentLandNode.ID
            };
            try
            {
                //后台数据访问
                objLandNode.LandId = objLandNodeManager.AddOneNodes(objLandNode);
                if (objLandNode.LandId > 0)
                {
                    inputLandNum(objLandNode);
                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
                else
                {
                    this.lblLandNum.Text = this.txtLandNum.Text.Trim() + "号地标已存在请重新输入!";
                    MessageBox.Show(this.txtLandNum.Text.Trim() + "号地标已存在，请重新输入", "添加提示");
                }
            }
            catch (Exception ex)
            {
                
                MessageBox.Show("添加失败！详细错误信息：" + ex.Message);
            }
            
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
